package com.x.provider.general.controller.rpc;

import com.x.core.web.api.R;
import com.x.provider.api.general.model.dto.gift.GiftCategoryDTO;
import com.x.provider.api.general.model.dto.gift.GiftRewardReqDTO;
import com.x.provider.api.general.service.GiftRpcService;
import com.x.provider.general.factory.dto.GeneralDTOFactory;
import com.x.provider.general.service.gift.GiftService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/rpc/gift")
public class GiftRpcController implements GiftRpcService {

    private final GiftService giftService;
    private final GeneralDTOFactory generalDTOFactory;

    public GiftRpcController(GiftService giftService,
                             GeneralDTOFactory generalDTOFactory){
        this.giftService = giftService;
        this.generalDTOFactory = generalDTOFactory;
    }

    @PostMapping("/reward")
    @Override
    public R<Void> giftReward(@RequestBody GiftRewardReqDTO giftRewardRequestDTO) {
        giftService.giftReward(giftRewardRequestDTO);
        return R.ok();
    }

    @PostMapping("/category/list")
    @Override
    public R<List<GiftCategoryDTO>> listGiftCategory() {
        return R.ok(generalDTOFactory.listGiftCategory());
    }
}
